<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Add index alias API | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'indices-add-alias.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/indices-add-alias.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/indices-add-alias.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/indices-add-alias.html" rel="nofollow" target="_blank">../en/indices-add-alias.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="rest-apis.html">REST APIs</a></span>
»
<span class="breadcrumb-link"><a href="indices.html">Index APIs</a></span>
»
<span class="breadcrumb-node">Add index alias API</span>
</div>
<div class="navheader">
<span class="prev">
<a href="indices.html">« Index APIs</a>
</span>
<span class="next">
<a href="indices-analyze.html">Analyze API »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="indices-add-alias"></a>Add index alias API<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/add-alias.asciidoc">edit</a>
</h2>
</div></div></div>

<p>Creates or updates an index alias.</p>
<p>An index alias is a secondary name
used to refer to one or more existing indices.</p>
<p>Most Elasticsearch APIs accept an index alias
in place of an index name.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /twitter/_alias/alias1</pre>
</div>
<div class="console_widget" data-snippet="snippets/1590.console"></div>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="add-alias-api-request"></a>Request<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/add-alias.asciidoc">edit</a>
</h3>
</div></div></div>
<p><code class="literal">PUT /&lt;index&gt;/_alias/&lt;alias&gt;</code></p>
<p><code class="literal">POST /&lt;index&gt;/_alias/&lt;alias&gt;</code></p>
<p><code class="literal">PUT /&lt;index&gt;/_aliases/&lt;alias&gt;</code></p>
<p><code class="literal">POST /&lt;index&gt;/_aliases/&lt;alias&gt;</code></p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="add-alias-api-path-params"></a>Path parameters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/add-alias.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">&lt;index&gt;</code>
</span>
</dt>
<dd>
<p>
(Required, string)
Comma-separated list or wildcard expression of index names
to add to the alias.
</p>
<p>To add all indices in the cluster to the alias,
use a value of <code class="literal">_all</code>.</p>
</dd>
<dt>
<span class="term">
<code class="literal">&lt;alias&gt;</code>
</span>
</dt>
<dd>
(Required, string)
Name of the index alias to create or update.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="add-alias-api-query-params"></a>Query parameters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/add-alias.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">master_timeout</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="common-options.html#time-units" title="Time units">time units</a>) Specifies the period of time to wait for
a connection to the master node. If no response is received before the timeout
expires, the request fails and returns an error. Defaults to <code class="literal">30s</code>.
</dd>
<dt>
<span class="term">
<code class="literal">timeout</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="common-options.html#time-units" title="Time units">time units</a>) Specifies the period of time to wait for
a response. If no response is received before the timeout expires, the request
fails and returns an error. Defaults to <code class="literal">30s</code>.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="add-alias-api-request-body"></a>Request body<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/add-alias.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">filter</code>
</span>
</dt>
<dd>
<p>
(Required, query object)
<a class="xref" href="query-dsl-bool-query.html" title="Boolean query">Filter query</a>
used to limit the index alias.
</p>
<p>If specified,
the index alias only applies to documents returned by the filter.
<a class="xref" href="query-dsl-bool-query.html" title="Boolean query">Filter query</a>
used to limit the index alias.</p>
<p>If specified,
the index alias only applies to documents returned by the filter.</p>
</dd>
<dt>
<span class="term">
<code class="literal">routing</code>
</span>
</dt>
<dd>
(Optional, string)
Custom <a class="xref" href="mapping-routing-field.html" title="_routing field">routing value</a>
used to route operations to a specific shard.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="add-alias-api-example"></a>Examples<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/add-alias.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="alias-adding"></a>Add a time-based alias<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/add-alias.asciidoc">edit</a>
</h4>
</div></div></div>
<p>The following request creates an alias, <code class="literal">2030</code>,
for the <code class="literal">logs_20302801</code> index.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /logs_20302801/_alias/2030</pre>
</div>
<div class="console_widget" data-snippet="snippets/1591.console"></div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="add-alias-api-user-ex"></a>Add a user-based alias<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/add-alias.asciidoc">edit</a>
</h4>
</div></div></div>
<p>First, create an index, <code class="literal">users</code>,
with a mapping for the <code class="literal">user_id</code> field:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /users
{
    "mappings" : {
        "properties" : {
            "user_id" : {"type" : "integer"}
        }
    }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1592.console"></div>
<p>Then add the index alias for a specific user, <code class="literal">user_12</code>:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /users/_alias/user_12
{
    "routing" : "12",
    "filter" : {
        "term" : {
            "user_id" : 12
        }
    }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1593.console"></div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="alias-index-creation"></a>Add an alias during index creation<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/add-alias.asciidoc">edit</a>
</h4>
</div></div></div>
<p>You can use the <a class="xref" href="indices-create-index.html#create-index-aliases" title="Aliases">create index API</a>
to add an index alias during index creation.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /logs_20302801
{
    "mappings" : {
        "properties" : {
            "year" : {"type" : "integer"}
        }
    },
    "aliases" : {
        "current_day" : {},
        "2030" : {
            "filter" : {
                "term" : {"year" : 2030 }
            }
        }
    }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1594.console"></div>
</div>

</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="indices.html">« Index APIs</a>
</span>
<span class="next">
<a href="indices-analyze.html">Analyze API »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>